package elements

import (
	"errors"
	"yizhuoyan/go-study/pdfgo/handyio"
)

type HeaderElement struct {
	version string
}

var versionKeywordBytes = []byte("%PDF-")

func (this *HeaderElement) Write(w handyio.PdfRawWriter) error {
	w.WriteBytes(versionKeywordBytes)
	w.WriteBytes([]byte(this.version))
	w.WriteEndOfLine()
	return nil
}

func (this *HeaderElement) Read(r handyio.PdfRawReader) error {
	if !r.NextBytesEquals(versionKeywordBytes) {
		return errors.New("非法header")
	}
	this.version = string(r.NextBytesUntilWhiteSpace())

	return nil
}
